package EA.testproblems;
import EA.*;

/**
   This testproblem is from De Jong's original test suite containing five
   functions. <br><br>

   <table border="0" cellpadding="2" cellspacing="0">
   <tr bgcolor="#a0a0a0">
   <td colspan="2" valign="top"><b>Problem description</b></td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top" width="200"><b>Name:</b></td>
   <td valign="top">De Jong F4</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Nickname:</b></td>
   <td valign="top">&nbsp;</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Intended usage:</b></td>
   <td valign="top">&nbsp;</td>
   </tr>

   <tr>
   <td colspan="2" valign="top">&nbsp;</td>
   </tr>
   <tr bgcolor="#a0a0a0">
   <td colspan="2" valign="top"><b>Problem details</b></td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Function:</b></td>
   <td valign="top">sum(1..30) (x<sub>i</sub><sup>4</sup>)</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Plots:</b></td>
   <td valign="top">Plot of the two dimensional De Jong F4<br>
   <img src="../../images/testproblems/dejongf4.gif">&nbsp;&nbsp;
   <img src="../../images/testproblems/dejongf4_contour.gif"></td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Dimensions:</b></td>
   <td valign="top">30</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Ranges:</b></td>
   <td valign="top">x<sub>i</sub> = [-1.28:1.28]</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Type:</b></td>
   <td valign="top">Minimization</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>No. of maximas:</b></td>
   <td valign="top">?</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>No. of minimas:</b></td>
   <td valign="top">1+</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Optima radius:</b></td>
   <td valign="top">0.2</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Optima descriptions:</b></td>
   <td valign="top">&nbsp;</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Known optimas:</b></td>
   <td valign="top">
   GMIN(0.0,0.0,...,0.0)
   <br><font size=1>Capital letters 
   means that the precise optima is known, lowercase letters is the best known 
   so far.</font></td>
   </tr>
   <tr>
   <td colspan="2" valign="top">&nbsp;</td>
   </tr>
   <tr bgcolor="#e0e0e0">
   <td valign="top"><b>Latex code:</b></td>
   <td valign="top">
   De Jong F4:<br>
   \[<br>
   f(\overline{x}) = \sum_{i=1}^{30} x_i^4\\[-2mm]<br>
   \]<br>
   where\\<br>
   \vspace*{-2mm}<br>
   \[<br>
   -1.28\leq{}x_i\leq{}1.28<br>
   \]<br>
   </td>
   </tr>

   </table>
*/

public class DeJongF4 extends NumericalProblem 
{

  // Easier way to build max and min
    private double[][] lmax = new double[0][2];
    private double[][] lmin = {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

  public DeJongF4()
    {
      super();

      double[] optimas;

      name = "De Jong function F4";
      objectivefunction = new NumericalFitness(){
	      public double Fitness_calcFitness_inner(double[] realpos)
	      {
		  double sum = 0;
		  for (int i=1; i<31; i++) {
			  sum += i*Math.pow(realpos[i-1],4);
		  }
		  
		  return sum;
	      };
	  };

      dimensions = 30;
      ismaximization = false;
      optimumradius = 0.2;

      intervals = new Interval[30];
      intervals[0] = new Interval(-1.28, 1.28);
      intervals[1] = new Interval(-1.28, 1.28);
      intervals[2] = new Interval(-1.28, 1.28);
      intervals[3] = new Interval(-1.28, 1.28);
      intervals[4] = new Interval(-1.28, 1.28);
      intervals[5] = new Interval(-1.28, 1.28);
      intervals[6] = new Interval(-1.28, 1.28);
      intervals[7] = new Interval(-1.28, 1.28);
      intervals[8] = new Interval(-1.28, 1.28);
      intervals[9] = new Interval(-1.28, 1.28);
      intervals[10] = new Interval(-1.28, 1.28);
      intervals[11] = new Interval(-1.28, 1.28);
      intervals[12] = new Interval(-1.28, 1.28);
      intervals[13] = new Interval(-1.28, 1.28);
      intervals[14] = new Interval(-1.28, 1.28);
      intervals[15] = new Interval(-1.28, 1.28);
      intervals[16] = new Interval(-1.28, 1.28);
      intervals[17] = new Interval(-1.28, 1.28);
      intervals[18] = new Interval(-1.28, 1.28);
      intervals[19] = new Interval(-1.28, 1.28);
      intervals[20] = new Interval(-1.28, 1.28);
      intervals[21] = new Interval(-1.28, 1.28);
      intervals[22] = new Interval(-1.28, 1.28);
      intervals[23] = new Interval(-1.28, 1.28);
      intervals[24] = new Interval(-1.28, 1.28);
      intervals[25] = new Interval(-1.28, 1.28);
      intervals[26] = new Interval(-1.28, 1.28);
      intervals[27] = new Interval(-1.28, 1.28);
      intervals[28] = new Interval(-1.28, 1.28);
      intervals[29] = new Interval(-1.28, 1.28);
      
      
      // Set up known maximas
      knownmaxima = new NumericalOptimum[lmax.length];

      for (int i=0;i<lmax.length;i++) {
	optimas = new double[dimensions];
	optimas[0] = lmax[i][0];
	optimas[1] = lmax[i][1];
	optimas[2] = lmax[i][2];
	knownmaxima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), true, false, i);
      }

      // Set up known minimas
      knownminima = new NumericalOptimum[lmin.length];

      for (int i=0;i<lmin.length;i++) {
	optimas = new double[dimensions];
	optimas[0] = lmin[i][0];
	optimas[1] = lmin[i][1];
	optimas[2] = lmin[i][2];
	knownminima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), false, false, i);
      }
    }
}
